#include <ctime>
#include "ThreadPool.hpp"
#include "Task.hpp"

int main()
{
    // 如果获取单例对象的时候，也是多线程获取的呢？
    std::cout << "process running ..." << std::endl;
    sleep(3);
    // ThreadPool<Task>* tp = new ThreadPool<Task>(5);
    ThreadPool<Task>::GetInstance()->Start();
    // tp->Start();
    srand(time(nullptr) ^ getpid());
    while(true)
    {   
        // 构建任务
        int x = rand() % 10 + 1;
        usleep(10);
        int y = rand() % 5 ;
        char op = opers[rand() % opers.size()];
        Task t(x, y, op);

        // sleep(1);
        // 交给线程池处理
        // tp->Push(t);
        ThreadPool<Task>::GetInstance()->Push(t);
        std::cout << "main thread make task: " << t.GetTask() <<  std::endl;
        sleep(1);
    }
    return 0;
}